

#include "SWidget/SInputGroupList.h"
#include "SWidget/SInputGroupButton.h"
#include "Input/InputConfigureLibrary.h"


#define LOCTEXT_NAMESPACE "WidgetGroupInputGroupListLog"

void SInputGroupList::Construct(const FArguments& InArgs)
{
	ChildSlot
		[
			SAssignNew(ListBox, SVerticalBox)
		];

	UpdateDetailsView = InArgs._UpdateDetailsView;
}



void SInputGroupList::UpdateList(bool OnlyUp)
{
	ListBox->ClearChildren();
	TArray<FString> Files;
	InputConfigureLibrary::FindInputConfigFiles(Files);

	for (size_t i = 0; i < Files.Num(); i++)
	{
		ListBox->AddSlot()
			.AutoHeight()
			[
				SNew(SInputGroupButton)
				.GroupKey(FPaths::GetBaseFilename(Files[i]))
			.ClickedEvent(this, &SInputGroupList::CallUpdateDetailsView)
			];
	}

	if (OnlyUp)
	{
		return;
	}

	if (Files.IsValidIndex(0))
	{
		CallUpdateDetailsView(FPaths::GetBaseFilename(Files[0]));
	}
}

void SInputGroupList::CallUpdateDetailsView(FString GroupKey)
{
	UpdateDetailsView.ExecuteIfBound(GroupKey);
}

#undef LOCTEXT_NAMESPACE

